package algotithm.leetcode.twopoint.test567;

/**
 * @author zhouyanxiang
 * @Date 2021-02-2021/2/10-11:54
 * @URL https://leetcode-cn.com/problems/permutation-in-string/submissions/
 * @Title 567. 字符串的排列
 */
public class Solution {

    public static void main(String[] args) {

    }

    public boolean checkInclusion(String s1, String s2) {
        int[] cnt = new int[26];
        int n = s1.length();
        int m = s2.length();
        if (n > m) {
            return false;
        }
        for (int i = 0; i < n; i++) {
            --cnt[s1.charAt(i) - 'a'];
        }
        int l = 0;
        for (int r = 0; r < m; r++) {
            int x = s2.charAt(r) - 'a';
            ++cnt[x];
            while (cnt[x] > 0) {
                --cnt[s2.charAt(l) - 'a'];
                ++l;
            }
            if (r - l + 1 == n) {
                return true;
            }
        }
        return false;
    }

}
